package com.leinao.media.runner;

import com.leinao.media.util.CommonUtils;
import com.leinao.media.utils.MediaUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * 项目启动时执行
 *
 * @author zhangyu
 * @date 2021/12/8 17:27
 */
@Component
@Slf4j
public class AppRunner implements ApplicationRunner {

    @Value("${sdk.enable.hk:true}")
    private boolean enableHk;

    @Value("${sdk.enable.dh:true}")
    private boolean enableDh;

    @Override
    public void run(ApplicationArguments args) {
        log.info("-----------ApplicationRunner-----------");
        // 1.SDK初始化
        int type = CommonUtils.getSdkEnableType(enableHk, enableDh);
        if (type == -1) {
            log.info("---未配置SDK启用,请在配置文件中开启海康或者大华SDK启用---");
        } else {
            MediaUtil.init(type);
        }
    }

}
